{{- if (.Values.global.enabledModules | has "operator-prometheus-crd") }}
  {{- range $version := .Values.istio.internal.operatorVersionsToInstall }}
    {{- $versionInfo := get $.Values.istio.internal.versionMap $version }}
    {{- $revision := get $versionInfo "revision" }}
---
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: istio-operator-{{ $revision }}
  namespace: d8-monitoring
  {{- include "helm_lib_module_labels" (list $ (dict "app" "operator" "prometheus" "main")) | nindent 2 }}
spec:
  selector:
    matchLabels:
      app: operator
      revision: {{ $revision }}
  namespaceSelector:
    matchNames:
    - d8-{{ $.Chart.Name }}
  podMetricsEndpoints:
  - port: http-metrics
    scheme: http
    #scheme: https # TODO https://github.com/deckhouse/deckhouse/issues/1487
    #bearerTokenSecret:
    #  name: "prometheus-token"
    #  key: "token"
    #tlsConfig:
    #  insecureSkipVerify: true
    relabelings:
    - targetLabel: job
      replacement: istio-operator
    - regex: endpoint|namespace|pod|service
      action: labeldrop
    - sourceLabels: [__meta_kubernetes_pod_label_revision]
      targetLabel: revision
    - targetLabel: tier
      replacement: cluster
    - sourceLabels: [__meta_kubernetes_pod_ready]
      regex: "true"
      action: keep
  {{- end }}
{{- end }}
